package com.elastic.documents;

import com.elastic.bean.Hotel;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Data
@NoArgsConstructor
public class HotelDoc {
    private Long id;
    private String name;
    private String address;
    private Integer price;
    private Integer score;
    private String brand;
    private String city;
    private String starName;
    private String business;
    private String location; //!
    private String pic;

    //距离
    private Object distance;
    //是否充广告
    private Boolean isAD;
    //ES中的completion，后面存数组，这里可以对应成List
    private List<String> suggestion;


    public HotelDoc(Hotel hotel) {   //有参构造，传入要封装的对象
        this.id = hotel.getId();  //对于这些不用包装的字段，直接get到后赋值给包装对象的属性就行
        this.name = hotel.getName();
        this.address = hotel.getAddress();
        this.price = hotel.getPrice();
        this.score = hotel.getScore();
        this.brand = hotel.getBrand();
        this.city = hotel.getCity();
        this.starName = hotel.getStarName();
        this.business = hotel.getBusiness();
        this.location = hotel.getLatitude() + ", " + hotel.getLongitude();   //注意这里
        this.pic = hotel.getPic();
        if(this.business.contains("/")){
            //此时business有多个值，需要分开后放入suggestion
            String[] arr = this.business.split("/");
            //添加元素
            this.suggestion = new ArrayList<>();
            Collections.addAll(this.suggestion,arr);
            this.suggestion.add(this.brand);
        }else{
            this.suggestion = Arrays.asList(this.brand,this.business);
        }
    }
}
